home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / liboctave / CmplxCHOL.cc < prev    next >
C/C++ Source or Header  |  1996-03-03  |  2KB  |  84 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if defined (__GNUG__)
  24. #pragma implementation
  25. #endif
  26.  
  27. #ifdef HAVE_CONFIG_H
  28. #include <config.h>
  29. #endif
  30.  
  31. #include "CmplxCHOL.h"
  32. #include "f77-fcn.h"
  33. #include "lo-error.h"
  34. #include "mx-inlines.cc"
  35.  
  36. extern "C"
  37. {
  38.   int F77_FCN (zpotrf, ZPOTRF) (const char*, const int&, Complex*,
  39.                 const int&, int&, long);
  40. }
  41.  
  42. int
  43. ComplexCHOL::init (const ComplexMatrix& a)
  44. {
  45.   int a_nr = a.rows ();
  46.   int a_nc = a.cols ();
  47.  
  48.   if (a_nr != a_nc)
  49.     {
  50.       (*current_liboctave_error_handler)
  51.     ("ComplexCHOL requires square matrix");
  52.       return -1;
  53.     }
  54.  
  55.   int n = a_nc;
  56.   int info;
  57.  
  58.   chol_mat = a;
  59.   Complex *h = chol_mat.fortran_vec ();
  60.  
  61.   F77_XFCN (zpotrf, ZPOTRF, ("U", n, h, n, info, 1L));
  62.  
  63.   if (f77_exception_encountered)
  64.     (*current_liboctave_error_handler) ("unrecoverable error in zpotrf");
  65.   else
  66.     {
  67.       // If someone thinks of a more graceful way of doing this (or
  68.       // faster for that matter :-)), please let me know!
  69.  
  70.       if (n > 1)
  71.     for (int j = 0; j < a_nc; j++)
  72.       for (int i = j+1; i < a_nr; i++)
  73.         chol_mat.elem (i, j) = 0.0;
  74.     }
  75.  
  76.   return info;
  77. }
  78.  
  79. /*
  80. ;;; Local Variables: ***
  81. ;;; mode: C++ ***
  82. ;;; End: ***
  83. */
  84.